home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / stuffit.arc / NEEDLEN.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-11-18  |  2.5 KB  |  101 lines

  1. ;NEEDLEN.ASM
  2. ;
  3. ;6.12.85
  4.  
  5. comment ~
  6.  
  7.         Compute length of file needed.
  8.  
  9.  
  10. Uses:
  11.     clavail         clusters available
  12.     hisiz           file size in bytes, high word
  13.     losiz           "          , low word    
  14.     bpc             bytes per cluster (word)
  15.  
  16. On output:
  17.     clneed          clusters needed: to be computed
  18.     clmake        clusters to be made by dummy file
  19.  
  20. Notes:
  21.     clusters needed = file size
  22.                       ------------          , rounded up to next whole cluster
  23.                       bytes per cluster
  24.  
  25.  
  26. This is a double word divided by word division operation (Reference p. 3-38)
  27.  
  28. ~
  29.  
  30. ;----------------------------------------------------------
  31. ;        constants and messages
  32.  
  33. needlen_msg    db    cr,lf,'needlen: ',eos
  34. zerodiv_msg    db    'zero divide error',cr,lf,eos
  35. nospace_msg    db    'not enough disk space',cr,lf,eos
  36.  
  37. ;----------------------------------------------------------
  38. ;        data storage
  39.  
  40. clneed      dw      0
  41. clmake      dw      0
  42.  
  43. ;----------------------------------------------------------
  44. ;        main code section
  45.  
  46. NEEDLEN        proc    near
  47.  
  48. clneeded:
  49.             mov     dx,hisiz                ;load most sig and..
  50.             mov     ax,losiz                ;..least sig parts of byte count
  51.             cmp     bpc,0                   ;check for imminent division by zero
  52.             jnz     divok
  53.         mov    dx,offset needlen_msg    ;error--div by zero
  54.         mov    ah,9h
  55.         int    21h
  56.         mov    dx,offset zerodiv_msg
  57.         mov    ah,9h
  58.         int    21h
  59.         mov    ax,99
  60.         jmp    nl_err
  61.  
  62. divok:      div     bpc                     ;divide by the bytes per cluster
  63.             cmp     dx,0                    ;if zero remainder..
  64.             je      clnok                   ;..do not need to round up
  65.             add     ax,1                    ;round up for the remainder
  66. clnok:      mov     clneed,ax
  67.             cmp     ax,clavail              ;compare with available
  68.             jna     okneed
  69.         mov    dx,offset needlen_msg    ;need more than available
  70.         mov    ah,9h            ;print string function call
  71.         int    21h
  72.         mov    dx,offset nospace_msg
  73.         mov    ah,9h
  74.         int    21h
  75.         mov    ax,99            ;special error return code        
  76.         jmp    nl_err
  77.  
  78. okneed: 
  79.             neg     ax                      ;change sign
  80.             add     ax,clavail
  81.             mov     clmake,ax
  82.         
  83. nlok_xit:    
  84.         clc                ;clear CY for ok return
  85.         ret
  86.  
  87. nl_err:
  88.         cmp    ax,99
  89.         je    nl_err99
  90.         push    ax        ;save error code
  91.         mov    dx,offset needlen_msg
  92.         mov    ah,9h
  93.         int    21h
  94.         pop    ax
  95.         call    errmsg
  96. nl_err99:    
  97.         stc
  98.         ret
  99.  
  100. needlen        endp
  101.